import { defHttp } from '/@/utils/http/axios';
import { stringFormat } from '/@/utils/common/compUtils';

enum Api {
  userEdit = '/api-upms/sys/user/update',
  queryNameByCodes = '/api-upms/sys/position/queryByCodes',
  updateMobile = '/api-upms/sys/user/putSysUserMobile/{0}/{1}',
  updateUserPassword = '/api-upms/sys/user/password',
  getTenantListByUserId = '/api-upms/sys/tenant/getTenantListByUserId',
  cancelApplyTenant = '/api-upms/sys/tenant/cancelApplyTenant',
  exitUserTenant = '/api-upms/sys/tenant/exitUserTenant',
  changeOwenUserTenant = '/api-upms/sys/tenant/changeOwenUserTenant',
  updateUserQuestion = '/api-upms/sys/user/putSysUserPwdQuestion',
  querySecurity = '/api-upms/sys/user/getSecurity/{0}',
  cancellationCurrentAccount = '/api-upms/sys/user/cancellationCurrentAccount',
  getCurrentMobile = '/api-upms/sys/user/getCurrentMobile',
  getCurrentEmail = '/api-upms/sys/user/getCurrentEmail',
  getThirdAccountByUserId = '/api-upms/sys/thirdApp/getThirdAccountByUserId',
  bindThirdAppAccount = '/api-upms/sys/thirdApp/bindThirdAppAccount',
  deleteThirdAccount = '/api-upms/sys/thirdApp/deleteThirdAccount',
  agreeOrRefuseJoinTenant = '/api-upms/sys/tenant/agreeOrRefuseJoinTenant',
}

/**
 * 用户编辑
 * @param params
 */
export const userEdit = (params) => {
  return defHttp.put({ url: Api.userEdit, params }, { isTransformResponse: false });
};

/**
 * 获取多个职务信息
 * @param params
 */
export const queryNameByCodes = (params) => {
  return defHttp.get({ url: Api.queryNameByCodes, params }, { isTransformResponse: false });
};

/**
 * 修改手机号
 * @param params
 */
export const updateMobile = (params) => {
  const url = stringFormat(Api.updateMobile, params.mobile, params.captcha);
  return defHttp.put({ url: url }, { isTransformResponse: false });
};

/**
 * 修改密码
 * @param params
 */
export const updateUserPassword = (params) => {
  return defHttp.put({ url: Api.updateUserPassword, params }, { isTransformResponse: false });
};

/**
 * 通过用户id获取租户列表
 * @param params
 */
export const getTenantListByUserId = (params) => {
  return defHttp.get({ url: Api.getTenantListByUserId, params }, { isTransformResponse: false });
};

/**
 * 取消申请
 * @param params
 */
export const cancelApplyTenant = (params) => {
  return defHttp.put({ url: Api.cancelApplyTenant, data: params }, { joinParamsToUrl: true, isTransformResponse: false });
};

/**
 * 用户退出租户
 * @param params
 */
export const exitUserTenant = (params) => {
  return defHttp.delete({ url: Api.exitUserTenant, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 变更租户拥有者
 * @param params
 */
export const changeOwenUserTenant = (params) => {
  return defHttp.post({ url: Api.changeOwenUserTenant, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 变更用户密保
 * @param params
 */
export const updateUserQuestion = (params) => {
  return defHttp.put({ url: Api.updateUserQuestion, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 获得用户安全信息
 * @param params
 */
export const querySecurity = (params) => {
  const url = stringFormat(Api.querySecurity, params.userid);
  return defHttp.get({ url: url, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 用户销户
 * @param params
 */
export const cancellationCurrentAccount = (params) => {
  return defHttp.put({ url: Api.cancellationCurrentAccount, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 获得当前用户手机号
 * @param params
 */
export const getCurrentMobile = (params) => {
  return defHttp.get({ url: Api.getCurrentMobile, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 获得当前用户电子邮箱
 * @param params
 */
export const getCurrentEmail = (params) => {
  return defHttp.get({ url: Api.getCurrentEmail, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 获取账号第三方信息通过第三方类型
 * @param params
 */
export const getThirdAccountByUserId = (params) => {
  return defHttp.get({ url: Api.getThirdAccountByUserId, params }, { isTransformResponse: false });
};

/**
 * 根据第三方uuid绑定账号
 * @param params
 */
export const bindThirdAppAccount = (params) => {
  return defHttp.post({ url: Api.bindThirdAppAccount, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 根据第三方uuid绑定账号
 * @param params
 */
export const deleteThirdAccount = (params) => {
  return defHttp.delete({ url: Api.deleteThirdAccount, params }, { isTransformResponse: false, joinParamsToUrl: true });
};

/**
 * 同意和拒绝加入租户
 * @param params
 */
export const agreeOrRefuseJoinTenant = (params) => {
  return defHttp.put({ url: Api.agreeOrRefuseJoinTenant, params }, { joinParamsToUrl: true });
};
